Ticket locks with enhanced waiting

ABSTRACT

A computer comprising one or more processors and memory may implement multiple threads that perform a lock operation using a data structure comprising an allocation field and a grant field. Upon entry to a lock operation, a thread allocates a ticket by atomically copying a ticket value contained in the allocation field and incrementing the allocation field. The thread compares the allocated ticket to the grant field. If they are unequal, the thread determines a number of waiting threads. If the number is above the threshold, the thread enters a long term wait operation comprising determining a location for long term wait value and waiting on changes to that value. If the number is below the threshold or the long term wait operation is complete, the thread waits for the grant value to equal the ticket to indicate that the lock is allocated.

This application claims priority to U.S. Provisional Application No. 62/734,687 filed Sep. 21, 2018 titled “Ticket Locks with Enhanced Waiting” which is herein incorporated by reference in its entirety.

BACKGROUND Field of the Disclosure

This disclosure relates generally to concurrent programming, and more particularly to systems and methods for performing concurrent synchronization using software lock operations.

Description of the Related Art

Modern computer systems conventionally include the ability to perform multiple threads of execution simultaneously, thus giving rise to the need to synchronize threads for access to shared data structures. Among these synchronization mechanisms is the lock operation. When using locks, data structures shared among multiple threads have an associated lock and, to access the shared data structure, a thread must first obtain the lock then release the lock once access is complete. Threads which attempt to obtain the lock while it is currently allocated to another thread must wait for the lock to become available.

Different approaches are used to implement such locking operations, among them is the ticket lock which includes a lock structure consisting of ticket and grant fields. Using a ticket lock, threads desiring to obtain the lock first allocate a ticket by atomically copying the ticket value from the lock structure and incrementing the ticket value in the lock structure. After the thread's ticket is allocated, the thread simply waits until the grant field of the lock structure equals the thread's ticket, indicating that the lock is allocated to the thread. Once the thread no longer needs the lock, it releases the lock by incrementing the grant field, which may indicate to another waiting thread that it has been allocated the lock.

The simple design of the ticket lock leads to efficient implementations resulting in low latencies in acquiring the lock, low latencies in the transfer of lock ownership from one thread to the next and allocation fairness for all threads. The ticket lock algorithm, however, suffers poor scalability when significant numbers of threads wait for the lock due to all threads waiting on the shared grant field causing significant memory contention when lock ownership is transferred. Other lock algorithms that provide similar fairness guarantees, such as the Mellor-Crummey and Scott, or MCS, lock address this issue to provide better scalability under higher thread contention, but these algorithms introduce additional complexity which increases latency in lock acquisition in periods of low contention. What is needed, then, is a locking operation which combines the simplicity and low latency of the ticket lock under low contention with the scalability benefits of other lock operations under periods of high lock contention.

SUMMARY

Methods, techniques and systems for providing efficient ticket locks with improved allocation waiting are described. These various embodiments of an enhanced ticket lock operation include the basic implementation of ticket locks, including a lock structure comprising ticket and grant fields and identical operation during periods of no or low contention for the lock, leading to the same low latency benefits of classic ticket lock operation. The various embodiments of an enhanced ticket lock operation also include the addition of one or more secondary wait variables; when a thread executing an enhanced ticket lock operation determines that it must enter a long term waiting operation due to lock contention, it determines a wait location to monitor for indication of long term wait completion. In doing so, contention for the shared grant field of the lock structure is substantially reduced or eliminated. By reducing contention of the grant field, the enhanced ticket lock operation substantially improves the high contention scalability of the ticket lock algorithm while preserving the low contention performance and fairness of the classic ticket lock.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram illustrating a system implementing an application execution environment including multiple threads sharing a resource through the use of ticket locks.

FIG. 2 is a state diagram illustrating one embodiment of a method for implementing a ticket lock operation augmented with a wait array.

FIG. 3 is a diagram illustrating the lock data structure used in one embodiment.

FIG. 4 is a flow diagram illustrating one embodiment of a method for implementing a ticket lock operation augmented with a wait array.

FIG. 5 is a diagram illustrating the lock data structure used in another embodiment.

FIG. 6 is a flow diagram illustrating another embodiment of a method for implementing a ticket lock operation augmented with a long term grant field.

FIG. 7 is a block diagram illustrating one embodiment of a computing system that is configured to implement enhanced ticket lock operations, as described herein.

While the disclosure is described herein by way of example for several embodiments and illustrative drawings, those skilled in the art will recognize that the disclosure is not limited to embodiments or drawings described. It should be understood that the drawings and detailed description hereto are not intended to limit the disclosure to the particular form disclosed, but on the contrary, the disclosure is to cover all modifications, equivalents and alternatives falling within the spirit and scope as defined by the appended claims. Any headings used herein are for organizational purposes only and are not meant to limit the scope of the description or the claims. As used herein, the word “may” is used in a permissive sense (i.e., meaning having the potential to) rather than the mandatory sense (i.e. meaning must). Similarly, the words “include”, “including”, and “includes” mean including, but not limited to.

Various units, circuits, or other components may be described as “configured to” perform a task or tasks. In such contexts, “configured to” is a broad recitation of structure generally meaning “having circuitry that” performs the task or tasks during operation. As such, the unit/circuit/component can be configured to perform the task even when the unit/circuit/component is not currently on. In general, the circuitry that forms the structure corresponding to “configured to” may include hardware circuits. Similarly, various units/circuits/components may be described as performing a task or tasks, for convenience in the description. Such descriptions should be interpreted as including the phrase “configured to.” Reciting a unit/circuit/component that is configured to perform one or more tasks is expressly intended not to invoke 35 U.S.C. § 112(f) interpretation for that unit/circuit/component.

This specification includes references to “one embodiment” or “an embodiment.” The appearances of the phrases “in one embodiment” or “in an embodiment” do not necessarily refer to the same embodiment, although embodiments that include any combination of the features are generally contemplated, unless expressly disclaimed herein. Particular features, structures, or characteristics may be combined in any suitable manner consistent with this disclosure.

DETAILED DESCRIPTION OF EMBODIMENTS

A ticket lock operation is a synchronization primitive for multi-threaded applications that employs a software lock in combination with an allocation strategy that ensures fairness. The ticket lock includes a lock structure consisting of ticket and grant fields. Using a ticket lock, threads desiring to obtain the lock first allocate a ticket by atomically copying a ticket value from the lock structure and incrementing the ticket value in the lock structure. After the ticket is allocated, the thread waits until the grant field of the lock structure equals the allocated ticket value, indicating that the lock is allocated to the thread. Once the thread no longer needs the lock, it releases the lock by incrementing the grant field, which may indicate to another waiting thread that it has been allocated the lock.

Various embodiments of the present invention extend the above ticket lock operation to use one or more wait variables for use by threads that have determined that they require long term wait operations. These one or more wait variables may be private to a particular lock or shared among multiple locks and may be statically sized dependent on anticipated workloads or may be sized in proportion to the number of processors in the host system.

Once a ticket has been allocated and the thread has determined that the lock is not yet available, the thread makes an additional determination whether a long term wait is required by determining if the number of threads already waiting on the lock exceeds a predetermined threshold. If the threshold is not exceeded, the thread proceeds in the same manner as in a conventional ticket lock, but if the threshold is exceeded the thread implements a long term wait using a separate wait variable rather than waiting on the grant field. In doing so, contention for the grant field is reduced or eliminated without increasing latency for low-contention conditions.

FIG. 1 is a block diagram illustrating a system implementing an application execution environment including multiple threads sharing a resource through the use of ticket locks. The System 100 includes one or more Processors 110 capable executing multiple parallel threads of execution coupled through one or more Caches 120 to a Memory 130 that includes an Application 140. The Application 140 may include multiple executing Threads 150 that access a Shared Resource 160. The Shared Resource 160 includes a controlling Lock Structure 170 and Resource Data 180 sharable by the Threads 150. To access Resource Data 180 of the Shared Resource 160, one of the Threads 150 must first allocate the Shared Resource 160 using the Lock Structure 170. Once the Shared Resource 160 is allocated, the Thread 150 may access the Resource Data 180 and when the Thread no longer requires access to the Shared Resource 160, the Thread 150 may release the Shared Resource 160 using the Lock Structure 170. While FIG. 1 shows a single application with three executing threads and one shared resource, this example is not intended to be limiting and any number of applications with any number of threads sharing any number of resources may be envisioned.

FIG. 2 is a state diagram illustrating an enhanced ticket lock operation according to some embodiments. A lock desired to be allocated by a thread may be described in by a lock structure 300 as shown in FIG. 3. This lock structure 300 includes two unsigned integer fields, a NextTicket field 310 and a Grant field 320. Initially, these two fields will be assigned equal values, typically zero, where equal values indicate that the lock is currently unallocated. When a thread allocates a ticket, it increments the NextTicket 310 field and assumes a ticket value equal to the NextTicket field 310 before the increment operation. Once this occurs, the NextTicket field 310 contains a value higher than the Grant field 320 indicating that the lock is allocated to the thread whose ticket value equals the Grant field 320 value. When the thread desires to release the lock, it increments the Grant field 320, indicating that either another thread is allocated the lock or that the lock is free, depending on the value of the NextTicket field 310. In this example, the NextTicket 310 and Grant 320 fields are monotonically increasing, except during integer overflows, by virtue of only being modified by increment operations. This means that the NextTicket 320 value is always greater than or equal to the Grant 320 value and the difference of these values is always non-negative. Those of ordinary skill in the art, however, will understand that this convention is only one of a number conventions that may be employed. For example, the NextTicket 310 and Grant 320 fields may each only be decremented resulting in monotonically decreasing values and ticket values less than or equal to the Grant field. Other conventions may also be employed and it should be understood that the conventions described above are not intended to be limiting.

A thread which desires to allocate a lock starts at the Begin state 200. In the Begin state 200, the thread first allocates a Ticket 201 by performing an atomic increment operation on the NextTicket field 310 of the desired lock. This may be performed using an atomic increment primitive, or instruction, that is a feature of many modern processor architectures. The atomic increment primitive loads the current value of a memory location, in this case the NextTicket field 310, increments the value contained in the memory location, and returns the value loaded which becomes the Ticket value for the thread. It should be understood, however, that an atomic increment primitive is not the only instruction usable to allocate the Ticket 201 and that any form of atomic update may also be used, particularly in computer architectures that don't directly provide an atomic increment primitive. Next, a number of waiting threads, dx, is computed in step 202. This value is simply one less than the difference between the allocated Ticket and the Grant field 320 and is a non-negative value representing the current number of waiting threads. If this value is zero (transition 207), then the thread has determined that the lock is allocated to the thread and execution proceeds to the Lock Allocated state 240. Alternatively, the allocated ticket may be directly compared to the Grant field 320 and, if equal, execution proceeds to the Lock Allocated state 240.

If it is determined that the lock is not yet allocated to the thread, then the number of waiting threads, dx, is computed if not already computed in step 201, and compared to a predetermined threshold. If the number of waiting threads is not above the threshold (transition 206), execution proceeds to Short Term Wait state 230. In the Short Term Wait state 230, the thread waits for the Grant field 320 to become equal to the allocated Ticket value. Once they are equal (transition 235) execution proceeds to the Lock Allocated state 240. If, however, the number of waiting threads exceeds the threshold (transition 205), execution proceeds to Long Term Wait state 210.

Once executing the Long Term Wait state 210, the thread first determines a memory location for a wait variable in step 211 on which to wait for completion of a long term wait operation. This determination may be implemented by means of one or more hash operations to compute the effective element of one or more arrays of memory variables. The hash operation may be performed on the allocated ticket value, alone or in combination with other information related to the lock. In some embodiments, the hash may comprise simple modulo operations dependent on the sizes of the one or more waiting arrays with these modulo operations performed on the ticket value itself, alone or as modified by other lock information. In other embodiments, the ticket value may first be modified so as to enable the hash to distribute consecutive ticket values among unique cache lines. For example, the ticket value may first be scaled by a prime number selected to be close to the size of a cache line of the underlying computer architecture. Any number of hash computations or other determination technique may also be employed and it should be understood that the hash computations described above are not intended to be limiting. Furthermore, the determination of the wait variable may be performed on entry to Long Term Wait state 210 during the transition 205 rather than each time the Long Term Wait state is entered, thus reducing the number of computations required during the long term wait operation of the thread.

Once the wait variable is determined, an initial value of the wait variable is read in step 211. After this value is read, the number of waiting threads, dx, is computed again in step 212 and, if the number of waiting threads remains above the threshold (transition 215), execution proceeds to Spin state 220 where the thread waits for the wait variable value determined in step 211 and loaded in step 211 to change. Once the wait value changes, execute returns to the Long Term Wait state 210. If, instead, the number of waiting threads is not above the threshold (transition 216), execution proceeds to Short Term Wait state 230. In the Short Term Wait state 230, the thread reads the Grant Field 231. Once the Grant field 320 to become equal to the allocated Ticket value. Once they are equal (transition 235) execution proceeds to the Lock Allocated state 240.

FIG. 4 is a state diagram illustrating an enhanced ticket lock operation according to some embodiments. A thread which desires to allocate a lock starts with allocating a Ticket 400 by performing an atomic increment operation on the NextTicket field 310 of the desired lock as discussed earlier in step 201 of Begin state 200 in FIG. 2. Next, the allocated ticket is compared to the Grant field 320 and, if equal, execution proceeds to the Lock Allocated state 480. If the allocated ticket is not equal to the Grant field 320, however, a number of waiting threads, dx, is computed and compared to a predetermined threshold 420. If the number of waiting threads is not above the threshold, execution proceeds to step 470 where the thread waits for the Grant field 320 to become equal to the allocated Ticket value. Once they are equal execution proceeds to the Lock Allocated state 480.

If, however, the number of waiting threads exceeds the threshold, execution proceeds to step 430 where the thread determines a memory location for a wait variable as discussed above in step 211 of the Long Term Wait state 210 in FIG. 2. Once the wait variable is determined, an initial value of the wait variable is read in step 440. After this value is read, the number of waiting threads, dx, is computed again in step 450 and, if the number of waiting threads remains above the threshold, execution proceeds to step 460 where the thread waits for the wait variable value to change. Once the wait value changes, execute returns to step 440. If, instead, the number of waiting threads is not above the threshold, execution proceeds to step 470 where the thread waits for the Grant field 320 to become equal to the allocated Ticket value. Once they are equal execution proceeds to the Lock Allocated state 480.

FIG. 5 is a diagram illustrating the lock data structure 500 used in other embodiments of an enhanced ticket lock operation. This lock structure includes three unsigned integer fields, a NextTicket field 510, a Grant field 520 and an LGrant field 530. The Grant field 520 and the LGrant field 530 may be organized such that the fields are associated with different cache lines in some embodiments. The NextTicket field 510 and Grant field 520 are analogous to the respective fields of the lock data structure 300 as describe above for FIG. 3 while the LGrant field 530 contains a value which tracks the Grant field 520 but is updated separately. When a thread desires to release the lock, it increments the Grant field 520, indicating that either another thread is allocated the lock or that the lock is free, depending on the value of the NextTicket field 510, but additionally performs an atomic increment of the LGrant field 530 subsequent to the incrementing of the Grant field 520. By providing separate Grant and LGrant fields, the number of threads waiting on a change of the Grant field can be minimized with long term waiting threads instead accessing the LGrant field.

FIG. 6 is a state diagram illustrating an enhanced ticket lock operation using a second Grant field according to some embodiments. A thread which desires to allocate a lock starts with allocating a Ticket 600 by performing an atomic increment operation on the NextTicket field 510 of the desired lock as discussed earlier in step 400 of FIG. 4. Next, the allocated ticket is compared to the Grant field 520 and, if equal, execution proceeds to the Lock Allocated state 680. If the allocated ticket is not equal to the Grant field 520, however, a number of waiting threads, dx, is computed and compared to a predetermined threshold 620. If the number of waiting threads is not above the threshold, execution proceeds to step 670 where the thread waits for the Grant field 520 to become equal to the allocated Ticket value. Once they are equal execution proceeds to the Lock Allocated state 680.

If, however, the number of waiting threads exceeds the threshold, execution proceeds to step 630 where the thread computes a number of waiting threads, dx, using the LGrant field 530 rather than the Grant field 520. If the number of waiting threads remains above the threshold in step 650, execution returns to step 630. If, instead, the number of waiting threads is not above the threshold, execution proceeds to step 670 where the thread waits for the Grant field 520 to become equal to the allocated Ticket value. Once they are equal execution proceeds to the Lock Allocated state 680.

Some of the mechanisms described herein may be provided as a computer program product, or software, that may include a non-transitory, computer-readable storage medium having stored thereon instructions which may be used to program a computer system 700 (or other electronic devices) to perform a process according to various embodiments. A computer-readable storage medium may include any mechanism for storing information in a form (e.g., software, processing application) readable by a machine (e.g., a computer). The machine-readable storage medium may include, but is not limited to, magnetic storage medium (e.g., floppy diskette); optical storage medium (e.g., CD-ROM); magneto-optical storage medium; read only memory (ROM); random access memory (RAM); erasable programmable memory (e.g., EPROM and EEPROM); flash memory; electrical, or other types of medium suitable for storing program instructions. In addition, program instructions may be communicated using optical, acoustical or other form of propagated signal (e.g., carrier waves, infrared signals, digital signals, etc.)

In various embodiments, computer system 700 may include one or more processors 760; each may include multiple cores, any of which may be single- or multi-threaded. For example, multiple processor cores may be included in a single processor chip (e.g., a single processor 760), and multiple processor chips may be included in computer system 700. Each of the processors 760 may include a cache or a hierarchy of caches 770, in various embodiments, for which the various aspects of the enhanced Ticket Lock operation may be tuned such as in step 430 of FIG. 4 and step 211 of FIG. 2. For example, each processor chip 760 may include multiple L1 caches (e.g., one per processor core) and one or more other caches (which may be shared by the processor cores on a single processor). The computer system 700 may also include one or more storage devices 750 (e.g. optical storage, magnetic storage, hard drive, tape drive, solid state memory, etc.) and one or more system memories 710 (e.g., one or more of cache, SRAM, DRAM, RDRAM, EDO RAM, DDR 10 RAM, SDRAM, Rambus RAM, EEPROM, etc.). In some embodiments, one or more of the storage device(s) 750 may be implemented as a module on a memory bus (e.g., on interconnect 740) that is similar in form and/or function to a single in-line memory module (SIMM) or to a dual in-line memory module (DIMM). Various embodiments may include fewer or additional components not illustrated in FIG. 7 (e.g., video cards, audio cards, additional network interfaces, peripheral devices, a network interface such as an ATM interface, an Ethernet interface, a Frame Relay interface, etc.)

The one or more processors 760, the storage device(s) 750, and the system memory 710 may be coupled to the system interconnect 740. One or more of the system memories 710 may contain application data 728 and program instructions 720. Application data 728 may contain various data structures to implement enhanced ticket locks while Program instructions 720 may be executable to implement one or more applications 722, shared libraries 724, and/or operating systems 726.

Program instructions 720 may be encoded in platform native binary, any interpreted language such as Java′ byte-code, or in any other language such as C/C++, the Java′ programming language, etc., or in any combination thereof. In various embodiments, applications 722, operating system 726, and/or shared libraries 724 may each be implemented in any of various programming languages or methods. For example, in one embodiment, operating system 726 may be based on the Java programming language, while in other embodiments it may be written using the C or C++ programming languages. Similarly, applications 722 may be written using the Java programming language, C, C++, or another programming language, according to various embodiments. Moreover, in some embodiments, applications 722, operating system 726, and/shared libraries 724 may not be implemented using the same programming language. For example, applications 722 may be C++ based, while shared libraries 724 may be developed using C.

Although the embodiments above have been described in considerable detail, numerous variations and modifications will become apparent to those skilled in the art once the above disclosure is fully appreciated. For example, although many of the embodiments are described in terms of particular types of operations that support synchronization within multi-threaded applications that access particular shared resources, it should be noted that the techniques and mechanisms disclosed herein for accessing and/or operating on shared resources may be applicable in other contexts in which applications access and/or operate on different types of shared resources than those described in the examples herein. It is intended that the following claims be interpreted to embrace all such variations and modifications.

In conclusion, multiple embodiments of an enhanced ticket lock are disclosed. With these enhancements, locking operations retain the advantages of classic ticket lock implementations, including low latency locking under low-contention conditions, while improving performance under high-contention conditions through improved transfer of ownership in the unlock path. Experimental results demonstrate that the enhanced ticket lock operation matches the performance of classic ticket locks, under conditions most favorable to classic ticket locks and in applications where ticket locks are traditionally preferred, while also meeting and often exceeding the performance of alternative locking approaches such as the MCS lock under high-contention conditions where the classic ticket lock traditionally suffers. For example, in a benchmark consisting of multiple threads executing a common critical section and contending for a single lock, the classic ticket lock, MCS lock and enhanced ticket lock exhibit similar performance for very low thread count. For increasing thread counts, the MCS lock exhibits higher latency and lower throughput but good scalability to very high thread counts while the classic ticket lock exhibits initially higher throughput but poor scalability and rapidly decline throughput at very high thread counts. In contrast, the enhanced ticket lock offers throughput significantly improved over the MCS lock and essentially matching the classic ticket lock while providing scalability equal to that of the MCS lock. For these reasons, the enhanced ticket lock provides significant performance advantages over traditional lock implementations. 

What is claimed:
 1. A method comprising: performing, by a thread of a plurality of threads executed on one or more processors, an operation to allocate a lock for exclusive access to a resource, comprising: allocating a ticket representing a position for allocating the lock; determining a number of threads of the plurality of threads waiting to allocate the lock; and responsive to the determined number of threads waiting to allocate the lock exceeding a threshold: selecting a location of a long term wait value, wherein the location of the long term wait value is different from a location of a grant value indicating a value of a ticket currently holding the lock; performing a long term wait operation comprising waiting for the long term wait value at the selected location to indicate that the number of threads waiting on the lock no longer exceeds the threshold; and performing a wait operation comprising waiting for the grant value to equal a value of the allocated ticket.
 2. The method of claim 1, the allocating the ticket representing the position for allocating the lock comprising executing an atomic fetch-and-add instruction on a next ticket field, wherein the atomic fetch-and-add instruction comprises atomically setting a value of the allocated ticket to a value fetched from the next ticket field and subsequently incrementing the next ticket field.
 3. The method of claim 1, the determining the number of threads of the plurality of threads waiting to allocate the lock further comprising computing a difference between the grant value and the value of the allocated ticket.
 4. The method of claim 1, the selecting the location of the long term wait value comprising selecting a long term grant location associated with the lock.
 5. The method of claim 1, the selecting the location of the long term wait value comprising selecting a location from a plurality of wait locations based at least in part on a result of a hash operation performed on the value of the allocated ticket.
 6. The method of claim 5, wherein the one or more processors comprise one or more memory caches, and wherein the hash operation performed on the value of the allocated ticket comprises distributing consecutive values of tickets to respective wait locations associated with respective different cache lines.
 7. The method of claim 1, further comprising: performing, by the thread of the plurality of threads executed on the one or more processors, an operation to release the lock for exclusive access to the resource, comprising incrementing the grant value.
 8. One or more non-transitory computer-accessible storage media storing program instructions that when executed on or across one or more processors cause the one or more processors to perform: executing, by a thread of a plurality of threads, an operation to allocate a lock for exclusive access to a resource, comprising: allocating a ticket representing a position for allocating the lock; determining a number of threads of the plurality of threads waiting to allocate the lock; and responsive to the determined number of threads waiting to allocate the lock exceeding a threshold: selecting a location of a long term wait value, wherein the location of the long term wait value is different from a location of a grant value indicating a ticket value currently holding the lock; performing a long term wait operation comprising waiting for the long term wait value at the selected location to indicate that the number of threads waiting on the lock no longer exceeds the threshold; and performing a wait operation comprising waiting for the grant value to equal a value of the allocated ticket.
 9. The one or more non-transitory computer-accessible storage media of claim 8, the allocating the ticket representing the position for allocating the lock comprising executing an atomic fetch-and-add instruction on a next ticket field, wherein the atomic fetch-and-add instruction comprises atomically setting a value of the ticket to a value fetched from the next ticket field and subsequently incrementing the next ticket field.
 10. The one or more non-transitory computer-accessible storage media of claim 8, the determining the number of threads of the plurality of threads waiting to allocate the lock further comprising computing a difference between the grant value and the value of the allocated ticket.
 11. The one or more non-transitory computer-accessible storage media of claim 8, the selecting the location of the long term wait value comprising selecting a long term grant location associated with the lock.
 12. The one or more non-transitory computer-accessible storage media of claim 8, the selecting the location of the long term wait value comprising selecting a location from a plurality of wait locations based at least in part on a result of a hash operation performed on the value of the allocated ticket.
 13. The one or more non-transitory computer-accessible storage media of claim 12, wherein the one or more processors comprise one or more memory caches, and wherein the hash operation performed on the value of the allocated ticket comprises distributing consecutive values of tickets to respective wait locations associated with respective different cache lines.
 14. The one or more non-transitory computer-accessible storage media of claim 8, the program instructions that when executed on or across one or more processors cause the one or more processors to further perform: executing, by the thread of the plurality of threads, an operation to release the lock for exclusive access to the resource, comprising incrementing the grant value.
 15. A system, comprising: one or more processors and a memory, the memory comprising program instructions executable by the one or more processors to perform, by a thread of a plurality of threads, an operation to allocate a lock, the operation to allocate the lock configured to: allocate a ticket representing a position for allocating the lock; determine a number of threads of the plurality of threads waiting to allocate the lock; and responsive to the determined number of threads waiting to allocate the lock exceeding a threshold: select a location of a long term wait value, wherein the location of the long term wait value is different from a location of a grant value indicating a ticket value currently holding the lock; perform a long term wait operation comprising waiting for the long term wait value at the selected location to indicate that the number of threads waiting on the lock no longer exceeds the threshold; and perform a wait operation comprising waiting for the grant value to equal a value of the allocated ticket.
 16. The system of claim 15, wherein to allocate the ticket representing the position for allocating the lock, the operation to allocate the lock configured to execute an atomic fetch-and-add instruction on a next ticket field, the atomic fetch-and-add instruction configured to set the ticket value to a value fetched from the next ticket field and subsequently increment the next ticket field.
 17. The system of claim 15, wherein to determine the number of threads of the plurality of threads waiting to allocate the lock, the operation to allocate the lock configured to compute the difference between the grant value and the value of the allocated ticket.
 18. The system of claim 15, wherein to select the location of the long term wait value, the operation to allocate the lock configured to select a long term grant location associated with the lock.
 19. The system of claim 15, wherein to select the location of the long term wait value, the operation to allocate the lock configured to select a location from a plurality of wait locations based at least in part on a result of a hash operation performed on the value of the allocated ticket.
 20. The system of claim 19, wherein the one or more processors comprise one or more memory caches, and wherein the hash operation is configured to distribute consecutive values of tickets to respective wait locations associated with respective different cache lines. 